import React from 'react'
import {
    StyleSheet, View, SafeAreaView, NativeEventEmitter, NativeModules
} from 'react-native'
import ComponentTabView from './tab/CommunityTabView'
import CommunityGuidesView from './guides/CommunityGuidesView'
import CommunityVideosView from './videos/CommunityVideosView'
import CommunityHotView from './hot/CommunityHotView'
import CommunityCitiesView from './cities/CommunityCitiesView'
import CommunityAllView from './all/CommunityAllView'
import FPSTool from './FPSTool'

const tabs = ['全部', '热门', '城市站', '攻略', '视频']

export default class Community extends React.Component {

    state = {
        tab: tabs[0]
    }

    render() {
        return (
            <SafeAreaView style={styles.safeAreaView} >
                <View style={styles.container}>
                    <ComponentTabView
                        dataList={tabs}
                        defaultTab={this.state.tab}
                        action={this.clickTabAction}
                    />
                    {this.getMainView()}
                    <FPSTool style={styles.fps} />
                </View>
            </SafeAreaView>
        )
    }

    clickTabAction = (item) => {
        this.setState({
            tab: item
        })
        // console.log('点击了tab：' + item)
    }

    getMainView() {
        if (this.state.tab == '攻略') {
            return <CommunityGuidesView />
        } else if (this.state.tab == '视频') {
            return <CommunityVideosView />
        } else if (this.state.tab == '城市站') {
            return <CommunityCitiesView />
        } else if (this.state.tab == '热门') {
            return <CommunityHotView />
        } else if (this.state.tab == '全部') {
            return <CommunityAllView />
        }
    }
}

const styles = StyleSheet.create({
    safeAreaView:{
        flex:1,
    },
    container: {
        flex: 1,
    },
    fps: {
        position: 'absolute',
    }
})
